﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using  Garlic.CC.BaseClass;
using Garlic.DM.DataModel;

namespace Garlic
{
    public partial class Frame_Header : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<MenuInfo> menuInfo = BLL.MenuManager.GetTopMenus(CurrentUser);
                //divMenu.Style["width"] = (menuInfo.Count * 108).ToString();
                ViewState["count"] = menuInfo.Count;
                //divMenu_right.Style["left"] = ((menuInfo.Count * 108) + 3).ToString();
                topMenu.DataSource = menuInfo;
                topMenu.DataBind();
                labLoginName.Text = CurrentUser.EmployeeName;//登陆人名。
                labData.Text = DateTime.Now.ToString("yyyy年MM月dd日");
                //ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>window.open()</script>");
                //$('.menu_ul li').eq('0').addClass('current').siblings('li').removeClass('current');
                
               
            }
        }

        public string GetCurrentMenuIndex()
        {
            int flg = 0;
            List<MenuInfo> menuInfo = BLL.MenuManager.GetTopMenus(CurrentUser);
            foreach (MenuInfo item in menuInfo)
            {
                if (Session["nav_menu_id"] != null && Session["nav_menu_id"].ToString() == item.Menu_id.ToString())
                {
                    break;
                }
                flg++;
            }
            return flg.ToString();
        }

        public string GetMenuInfo()
        {
            return ViewState["count"].ToString();
           
        }

        protected void topMenu_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            //Session["topMenuKey"] = e.CommandArgument as string;
            //Page.RegisterClientScriptBlock("", "<script>alert('" + Session["topMenuKey"].ToString() + "')</script>");
        }
        protected void topMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            string menuID = ((Garlic.DM.DataModel.MenuInfo)(e.Item.DataItem)).Menu_id.ToString();
            if (Request["parentMenuID"] == menuID)
            {
               // this.SetSelectedMenu(menuID);
            }
            
        }

        protected void btnLogout_Click(object sender, EventArgs e)
        {
            
            Session[BasePage.SessionKey_CurrentUser] = null;
            Response.Redirect("Default.aspx");
        }
    }
}